package com.longshen.dubbo.api.sequence;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import lombok.Data;

@Data
@Service("sequenceService")
public class SequenceService {

	private SnowflakeIdWorker idWorker;

	@PostConstruct
	public void init() {
		idWorker = new SnowflakeIdWorker(0, 0);
	}

	public String getId() {
		long seqNum = idWorker.nextId();
		String seqid = StringUtils.leftPad(String.valueOf(seqNum), 20, '0');
		return seqid;
	}

}
